#include "model_SPDE2D.h"
#include "../Main/Source.h"
#include "../Main/Sink.h"
#include "../Controller/controller_MPC_IPOPT.h"

/*int main()
{
	model_SPDE2D wafer(20,100,1);
	//source_fromfile Input_T("Input_T.dat");
	Sink_ToFile Output_R2("Output_R2.dat",200,5);
	
	double time  = 0.0;
	double dt    = 1;
	double t_end = 200.0;
	double R2;

	while(time<=t_end)
	{
		R2 = wafer.getR2();
		wafer.update(time,0.5,610);		
		Output_R2.update(time,R2);
		time += dt;
	}
	wafer.getZmean("Output_Mode_t200.dat");
}*/
// -----------------------------------------------------
/*int main()
{
	model_SPDE2D wafer(20,100,5);
	source_fromfile Input_T("Input_T.dat");
	Sink_ToFile Output_R2("Output_R2.dat",100,5);
	
	double time  = 0.0;
	double dt    = 5.0;
	double t_end = 100.0;
	double R2;

	while(time<=t_end)
	{	
		T  = Controller.getT();
		W  = Controller.getW();
		R2 = wafer.getR2();
		wafer.update(time,W,T);		
		Output_R2.update(time,R2);
		time += dt;
	}
}*/
// -----------------------------------------------------
int main()
{
	plant_SPDE2D wafer(20,100,5);
	controller_MPC_IPOPT controller(20,5);

	controller.ConnectInputTo(0,wafer,0);
	wafer.ConnectInputTo(1,controller,0);
	wafer.ConnectInputTo(0,controller,1);

	double time  = 0.0;
	double dt    = 1;
	double t_end = 100.0;
	Sink_ToFile Output_R2("Output_R2",100.0,1);
	Sink_ToFile Output_T("Output_T",100.0,1);
	Sink_ToFile Output_W("Output_W",100.0,1);
	Sink_ToFile Output_H("Output_H",100.0,1);
	Sink_ToFile Output_M2("Output_M2",100.0,1);
	double R2;
	double H;
	double** u = NULL;
	double T;
	double W;

	while(time<=t_end)
	{
		controller.update(time);
		wafer.update(time);		

		R2 = wafer.getR2();
		H  = wafer.getH();
		T = controller.getOutput1();
		W = controller.getW();

		Output_R2.update(time,R2);
		Output_H.update(time,H);
		Output_T.update(time,T);
		Output_W.update(time,W);
		Output_M2.update(time,wafer.getM2());

		time += dt;
	}

	/*while(time<=t_end)
	{
		R2 = wafer.getR2();

		wafer.update(time,0.5,615);		
		Output_R2.update(time,R2);
		time += dt;
	}*/
	wafer.getZmean("Output_Mode_t200.dat");
}